package com.action;

import com.opensymphony.xwork2.ActionSupport;
import lombok.Data;
import lombok.extern.log4j.Log4j2;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by Administrator on 2017/2/24.
 */
@Data
@Log4j2
public class UserAction extends ActionSupport{
    private String name;
    public void show() throws IOException {
        HttpServletResponse resp = ServletActionContext.getResponse();
        HttpServletRequest req = ServletActionContext.getRequest();
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        out.print("<!DOCTYPE html>");
        out.print("\n<html>");
        out.print("\n<head>");
        out.print("\n<title>struts拦截器</title>");
        out.print("\n</head>");
        out.print("\n<body>");
        out.print("\n<h1>Hello</h1>");
        out.print("\n</body>");
        out.print("\n</html>");
        out.println(req.getSession().getAttribute("admin"));
        out.flush();
        out.close();

        log.info("name="+name);
    }
    public void yy() throws IOException {
            HttpServletResponse resp = ServletActionContext.getResponse();
            HttpServletRequest req = ServletActionContext.getRequest();
            resp.setCharacterEncoding("utf-8");
            resp.setContentType("text/html;charset=utf-8");
            PrintWriter out = resp.getWriter();
            out.print("<!DOCTYPE html>");
            out.print("\n<html>");
            out.print("\n<head>");
            out.print("\n<title>struts拦截器</title>");
            out.print("\n</head>");
            out.print("\n<body>");
            out.print("\n<h1>Hello</h1>");
            out.print("\n<h3 style='color:red'>"+ req.getParameter("name"));
            out.print("\n</h3>");
            out.print("\n</body>");
            out.print("\n</html>");
            out.print(name);
            out.flush();
            out.close();
            System.out.println("--");
            System.out.println("--");
            System.out.println("--");
            System.out.println("--");
            System.out.println("--");
            System.out.println("--");
            System.out.println("--");
            System.out.println("--");
            System.out.println("--");

        }
}
